package com.wangzh.concurrent.lock.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class CallableTest {
    public static void main(String[] args) throws Exception {


        MyCallable myCallable = new MyCallable();
//        myCallable.call();
        FutureTask<Integer> futureTask = new FutureTask<>(myCallable);

        new Thread(futureTask,"a").start();

        System.out.println(futureTask.get());//能够获取结果，包括异常信息，会产生阻塞，

        System.out.println("阻塞测试");
    }
}

class MyCallable implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        System.out.println("call:"+Thread.currentThread().getName());
        TimeUnit.SECONDS.sleep(2);

//        int a = 1/0;
        return 1;
    }
}
